package com.ctu.gzero.properties
{
	public class NumberOrPercentOrEnumProperty extends NumberOrPercentProperty
	{
		private var _range:Object;
		private var _defaultValue:Object;
		
		public function NumberOrPercentOrEnumProperty(name:String, object:Object, min:Number, max:Number,
				minPer:String, maxPer:String)
		{
			_range = new Object();
			
			var s:Object = _range;								
			var i:int = 0;		
							
			while(i < s.length)
			{
				_range[s[i]] = null;
				i++;
			}
			
			if(object is String)
			{
				if(_range.hasOwnProperty(object))
				{
					_defaultValue = object;
				}
			}
			
			super(name, object,min,max,minPer,maxPer);
		}
		
		override public function get defaultValue():Object		
		{
			var _obj:Object = (_defaultValue==null) ?  super.defaultValue : _defaultValue;
			return _obj;
		}
		
		override public function hash(obj:Object, code:uint):uint
		{
			if(obj is String)
			{
				if(_range.hasOwnProperty(obj))
				{
					return StringProperty.doHash(obj as String, code);
				}
			}
			return super.hash(obj, code);
		}
		
		override public function setHelper(obj1:Object, obj2:Object):Object
		{
			if(obj2==null)
			{
				return obj2;
			}
			
			var _obj:Object = (_range.hasOwnProperty(obj2)) ?  obj2 : super.setHelper(obj1, obj2);
			return _obj;
		}
		
		override public function valueFromString(value:String):Object
		{
			var _obj:Object = super.valueFromString(value);
			if(_obj==null)
			{
				return value;
			}
			
			return _obj;
		}
		
		public function get range():Object
		{
			return Property.shallowCopy(_range);
		}
	}
}